// Author  : Morbid
// Time    : 2022/04/30 20:02
// FileName: Main_66.java
// Software: IntelliJ IDEA

package LeetCode;

import java.util.Arrays;

public class Main_66 {
    //66. 加一
    static int[] plusOne(int[] digits) {
        int p = digits.length - 1;
        while (p >= 0) {
            if (digits[p] == 9) {
                digits[p] = 0;
            } else {
                digits[p] = digits[p] + 1;
                return digits;
            }
            p--;
        }
        int[] arr = new int[digits.length + 1];
        arr[0] = 1;
        return arr;
    }

    public static void main(String[] args) {
        int[] digits = {4, 3, 2, 1};
        System.out.println(Arrays.toString(plusOne(digits)));
    }
}
